/**
 * 新增题目列表
 */
saveQuestion = function() {
	var subNum = $("#bh").attr("value");
	// 校验是否是正整数
	var regu = "^[0-9]+$";
	var re = new RegExp(regu);
	if (subNum.search(re) != -1) {
	} else {
		alert("编号只能是正整数");
		return;
	}
	var title = $("#title").attr("value");
	if (title == '') {
		alert("标题不能为空");
		return;
	}
	var subject_id = $("#subject_id").attr("value");

	var subType = $("#subType").attr("value");

	var totalTime = $("#timeLimt").attr("value");
	var content = $("#content").attr("value");

	var filePath = $("#uploadify_file").attr("value");

	var all_words = $("#all_words").attr("value");

	var target_words = $("#target_words").attr("value");

	var correct = $("#correctOption").attr("value");
	if (subType == "10" ) {
		if (totalTime == '') {
			alert("答题时间不能为空");
			return;
		}
		
		if (content == '') {
			alert('题干不能为空');
			return;
		}

	} else if (subType == "6"  || subType == "13") {
		if (totalTime == '') {
			alert("答题时间不能为空");
			return;
		}
		content = editor.getPlainTxt();
		if (content == '') {
			alert('题干不能为空');
			return;
		}

	}else if (subType == "4" || subType == "5") {

		if (filePath == '') {
			alert("上传内容不能为空");
			return;
		}
		if (content == '') {
			alert("选项不能为空");
			return;
		}
		if (correct == '') {
			alert("正确答案不能为空");
			return;
		}
	} else if (subType == "3") {

		if (target_words == '') {
			alert("上传内容不能为空");
			return;
		}
		if (all_words == '') {
			alert("上传内容不能为空");
			return;
		}
		if (correct == '') {
			alert("正确答案不能为空");
			return;
		}
	} else if (subType == "7" || subType == "8" || subType == "2"
			) {

		if (target_words == '') {
			alert("上传内容不能为空");
			return;
		}
		if (all_words == '') {
			alert("上传内容不能为空");
			return;
		}

	}else if (subType == "9") {

		if (content == '') {
			alert("问题不能为空");
			return;
		}
		
		if (correct == '') {
			alert("答案不能为空");
			return;
		}

	} else if (subType == "11") {

		if (target_words == '') {
			alert("符号不能为空");
			return;
		}
		if (all_words == '') {
			alert("数字不能为空");
			return;
		}
		if (totalTime == '') {
			alert("答题时间不能为空");
			return;
		}
	} else if (subType == "12") {

		if (filePath == '') {
			alert("图形不能为空");
			return;
		}
		if (correct == '') {
			alert("答案不能为空");
			return;
		}
		if (content == '') {
			alert("题干不能为空");
			return;
		}
		if (totalTime == '') {
			alert("答题时间不能为空");
			return;
		}
	} else if (subType == "1") {
		if (totalTime == '') {
			alert("答题时间不能为空");
			return;
		}
	} else if (subType == "14" || subType == "15" || subType == "16") {

		if (filePath == '') {
			alert("上传内容不能为空");
			return;
		}

	}

	// 获取checkbox选项
	var courses = $("#CheckboxGroup1_0").attr("value");
	if (courses == '') {
		alert("必须选择类别");
		return;
	}
	var courseIds = getValuesByJqueryObjs($(".course_add td input[name=courseId]:checked"));
	if (courseIds == '') {
		alert("必须选择类别");
		return;
	}
	var ageIds = getValuesByJqueryObjs($(".course_add td input[name=ageId]:checked"));
	if (ageIds == '') {
		alert("必须选择年龄段");
		return;
	}
	var ages = $("#CheckboxGroup2_0").attr("value");
	if (ages == '') {
		alert("必须选择年龄段");
		return;
	}
	// 获取难易程度
	var diffcult = $("#diffcultySelection").val();
	var scores = $("#score").attr("value");
	if (scores == '') {
		alert("分值不能为空");
		return;
	}

	$.post(_contextPath + "/admin/addSubject.htm", {
		"SUBNUM" : subNum,
		"CONTENT" : content,
		"CORRECT" : correct,
		"COURSES" : courseIds,
		"AGES" : ageIds,
		"diffcult" : diffcult,
		"score" : scores,
		"filePath" : filePath,
		"subType" : subType,
		"title" : title,
		"totalTime" : totalTime,
		"target_words" : target_words,
		"all_words" : all_words,
		"subject_id" : subject_id

	}, function(ms) {
		var obj = JSON.parse(ms);
		if (obj.status == 'success') {
			alert(obj.message);
			setTimeout(function() {
				window.location.href = _contextPath
						+ "/admin/goSubjectList.htm";
			}, 1000);
		} else if (obj.status = 'error') {
			alert(obj.message);
		}
	});

};







